import { useEffect, useState } from 'react';

export const useMount = (callback: Function, cleanFunc?: Function) => {
  useEffect(() => {
    const clean = callback();
    return () => {
      clean?.();
    };
  }, []);
};

export const useDebounce = <T>(value: T, delay: number): T => {
  const [valueDebounce, setValueDebounce] = useState<T>(value);
  useEffect(() => {
    let timeout = setTimeout(() => setValueDebounce(value), delay);
    return () => {
      clearTimeout(timeout);
    };
  }, [value, delay]);
  return valueDebounce;
};
